import cn.itcast.po.User;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

public class ReflectDemo {

    public static void main(String[] args) throws Exception {
//        System.out.println(createInstance(User.class));
        User user = new User();
        invokeMethod(user, "show", null);
    }

    private static Object createInstance(Class clazz) throws Exception{
        Constructor constructor = clazz.getConstructor(String.class);
        return constructor.newInstance("crisfan");  // 反射生成对象
    }

    private static void invokeMethod(Object obj, String methodName, Class... parameterType)throws Exception{
        Method method = obj.getClass().getMethod(methodName, parameterType);
        method.invoke(obj, null);
    }
}
